<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组的去重</title>
</head>
<body>
<script>
    /* es6的Set语法
     let arr = [1,3,4,5,6,7,6,8,5,3]
     let newArr = [...new Set(arr)]
     console.log(newArr)*/

    let arr = [1, 3, 4, 5, 6, 7, 6, 8, 5, 3,9999,999,99999,999]

    /*// 利用indexOf
    function quchong(array) {
        // 创建一个对新数组用来保存去重后数组
        let newArr = []
        for (let i = 0; i < array.length; i++) {// 对传进来的数组的每一项遍历
            if (newArr.indexOf(array[i]) === -1) {
                newArr.push(array[i])
            }
        }
        return newArr
    }*/

    // 利用includes去重
    function quchong(arr){
        if(!Array.isArray(arr)){
            console.log('这不是数组')
            return
        }

        let newArr = []
        for(let i=0;i<arr.length;i++){
            if(!newArr.includes(arr[i])){
                newArr.push(arr[i])
            }
        }
        return newArr
    }


    console.log(quchong(arr))

</script>
</body>
</html>
